<?php

namespace App\Services\PayAndConsume;

use App\Models\Enum\ActionDef;
use Auth;
use App\Repositories\PayAndConsume\HotspotRepository;
use App\Models\Enum\RedPacket;

class HotspotService
{
    public function __construct(HotspotRepository $hotspotRepository)
    {
        $this->hotspotRepository = $hotspotRepository;
    }

    public function create($request)
    {
        $datas = $request->all();

        $result = $this->hotspotRepository->create($datas);

        return $result;
    }

    //获取热点数据
    public function getHotspotData($request)
    {
        $merge = [];
        $deviceNum = $this->getEnterUrlDevice($request);
        $actionUid = $this->getActionUid($request);

        foreach ($deviceNum as $value) {
            $merge[$value['channel_id']][ActionDef::ENTER_URL] = $value['device_sum'];
        }

        foreach ($actionUid as $value) {
            $merge[$value['channel_id']][$value['action_id']] = $value['uid_sum'];
        }

        return $merge;
    }

    //获取进入游戏的设备数
    public function getEnterUrlDevice($request)
    {
        $data = $this->hotspotRepository->getEnterUrl($request);
        $data = $data->toArray();

        return $data;
    }

    //获取进入游戏的Action
    public function getActionUid($request)
    {
        $data = $this->hotspotRepository->getActionUid($request);
        $data = $data->toArray();

        return $data;
    }
}